/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.filecenter.model.entity;

import cn.hallele.mc.sdk.filecenter.common.enums.FileTypeEnum;
import jakarta.persistence.*;
import lombok.*;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * hallele_ms_filecenter
 *
 * @author anle5
 * @since 2024/9/24 0:33
 */
@Getter
@Setter
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "fc_file")
public class FileEntity implements Serializable {
    @Serial
    private static final long serialVersionUID = 8592857639785650981L;

    /**
     * 身份唯一标识
     * 生成策略: 从表key_generator中读取
     * name: TableGenerator唯一标识
     * pkColumnName：生成策略所对应键值的名称
     * pkColumnValue：键当前所生成的值，它的值将会随着每次创建累加
     * initialValue: 初始值
     * allocationSize: 递增至
     */
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "ApiLogEntity")
    @TableGenerator(name = "ApiLogEntity",
            table = "key_generator",
            pkColumnName = "gen_name",
            valueColumnName = "gen_value",
            pkColumnValue = "fc_file",
            initialValue = 1,
            allocationSize = 1
    )
    @Column(name = "id")
    private Long id;

    /**
     * 文件名
     */
    @Column(name = "filename")
    private String filename;

    /**
     * 文件路径
     */
    @Column(name = "filepath")
    private String filepath;

    /**
     * 业务类型,用于做存储路劲映射
     */
    @Column(name = "action")
    private String action;

    /**
     * 文件访问地址
     */
    @Column(name = "url")
    private String url;

    /**
     * 文件md5
     */
    @Column(name = "md5")
    private String md5;

    /**
     * 文件类型
     */
    @Column(name = "filetype")
    private FileTypeEnum filetype;

    /**
     * 文件临时访问地址
     */
    @Column(name = "temp_url")
    private String tempUrl;

    /**
     * 文件临时访问地址过期时间，单位 s
     */
    @Column(name = "expires")
    private Integer expires;

    /**
     * 文件大小 byte
     */
    @Column(name = "file_size")
    private Long fileSize;

    /**
     * 文件上传者
     */
    @Column(name = "initiator")
    private Long initiator;

    /**
     * 文件更新时间
     */
    @Column(name = "update_time")
    private Date updateTime;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private Date createTime;

    /**
     * 版本号
     */
    @Version
    @Column(name = "version")
    private Integer version;
}
